package com.example.demo.mq;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

@Component
public class PayProducer {
    //生产组
    private String producerGroup = "fx_test_group";

    private DefaultMQProducer producer;

    public PayProducer() {
        System.out.println("PayProducer");
//        producer = new DefaultMQProducer(producerGroup);
//
//        //多个NameServer地址 多个地址 ; 号隔开
//        producer.setNamesrvAddr(JmsConfig.nameServerAddr);
//        start();
    }

    /**
     * 开始
     */
    public void start(){
        System.out.println("PayProducer start");
        try {
            this.producer.start();
        } catch (MQClientException e) {
            e.printStackTrace();
        }
    }

    public DefaultMQProducer getProducer(){
        return this.producer;
    }

    /**
     * 一般关闭上下文是关闭
     */
    @PreDestroy
    public void shutdown(){
        System.out.println("PayProducer 关闭....");
        this.producer.shutdown();
    }
}
